import { Controller, Get, Render } from '@nestjs/common';
import { posts } from '../../main';
@Controller('posts')
export class PostsController {
  @Get()
  @Render('post')
  getData() {
    return { items: posts };
  }

  @Get('add')
  addData() {
    posts.push({ title: '新增文章' });
    return 'success';
  }

  @Get('del')
  delData() {
    posts.pop();
    return 'success';
  }

  @Get('mod')
  modData() {
    if (posts.length > 0) {
      posts[0].title = 'xxx';
    }
    return 'success';
  }

  @Get('find')
  findData() {
    return JSON.stringify(posts);
  }
}
